package com.globallogic.week3.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.globallogic.week3.util.AuthUserHandler;

@WebServlet(urlPatterns="/logout")
public class LogoutServlet extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		AuthUserHandler authUserHandler = (AuthUserHandler) req.getServletContext().getAttribute("authUserHandler");
		HttpSession session = req.getSession();
		
		authUserHandler.remove((String)session.getAttribute("isAuth"));
		session.setAttribute("isAuth", null);
		session.invalidate();
		req.getRequestDispatcher("/").forward(req, resp);
	}

}
